package com.qidianit.task.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidianit.task.mapper.ProjectMapper;
import com.qidianit.task.pojo.Project;
import com.qidianit.task.service.ProjectService;
import com.qidianit.task.util.Constant;
import com.qidianit.task.util.pojo.QdResult;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author gfdycxy
 * @Company cxy
 * @Description
 * @Time 2024/9/5 18:41
 */
@Service
public class ProjectServiceImpl implements ProjectService {
    @Autowired
    private ProjectMapper projectMapper;
    @Override
    public QdResult queryByPage(Project project, Integer page, Integer limit) {
        // 开启分页  参数1： 页码  参数2： 每页大小
        PageHelper.startPage(page,limit);
        // 查询全部
        List<Project> projects = projectMapper.queryByPage(project);
        for (Project project1 : projects){
            project1.setCountTasks(projectMapper.countTasks(project1));
        }
        // 创建一个PageInfo对象，构造方法中传入查询的结果集合。
        PageInfo<Project> pageInfo = new PageInfo<>(projects);
        // 将pageInfo对象设置到qdResult中
        return QdResult.success(pageInfo);
    }
    @Override
    public QdResult insertNewProject(Project project) {
        return projectMapper.insertNewProject(project) == 1?QdResult.success():QdResult.error();
    }

    @Override
    public QdResult selectByProjectId(String projectId) {


        return QdResult.success(projectMapper.selectByProjectId(projectId));

    }

    @Override
    public QdResult updateById(Project project) {
        return projectMapper.updateById(project) == 1?QdResult.success():QdResult.error();
    }

    @Override
    public QdResult queryById(String projectId) {
        return QdResult.success(projectMapper.selectByProjectId(projectId));
    }

    @Override
    public QdResult deleteById(String projectId) {
        return projectMapper.deleteById(projectId)== 1?QdResult.success():QdResult.error();
    }
/////////////////////////
    @Override
    public QdResult archiveById(String projectId) {
        return QdResult.isSuccess(projectMapper.archiveById(projectId));
    }

    @Override
    public QdResult releases(String [] projectId) {
        return QdResult.success(200,"ok",projectMapper.releasesById(projectId));
    }

    @Override
    public QdResult archives( String[] projectId) {
    return QdResult.success(200,"ok",projectMapper.archivesById(projectId));
    }

    @Override
    public QdResult deletes(String[] projectId) {
        return QdResult.success(200,"ok",projectMapper.deletesById(projectId));

    }
    @Override
    public QdResult queryDeletes(Project project,int page,int limit) {
        // 开启分页  参数1： 页码  参数2： 每页大小
        PageHelper.startPage(page,limit);
        // 查询全部
        List<Project> projects = projectMapper.selectDeletes(project);
        // 创建一个PageInfo对象，构造方法中传入查询的结果集合。
        PageInfo<Project> pageInfo = new PageInfo<>(projects);
        // 将pageInfo对象设置到qdResult中
        return QdResult.success(pageInfo);
    }
    @Override
    public QdResult reReleases(String [] ids) {
        return QdResult.success(200,"ok",projectMapper.updateStatusByIds(ids));

    }
}